package cn.zptc.springbootdemo.web;

/**
 * @author ：zhaoweiwei
 * @date ：创建于 2025/3/17 14:39
 * @description：
 * @modified By：
 * @version: 1.0.0
 */

import cn.zptc.springbootdemo.domain.Book;
import cn.zptc.springbootdemo.domain.Comment;
import cn.zptc.springbootdemo.domain.Data;
import cn.zptc.springbootdemo.domain.User;
import cn.zptc.springbootdemo.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;

@Controller
@RequestMapping("comment")
public  class CommentController {

    @Autowired
    private CommentService commentService;

   /* @PostMapping("/update")
    //@GetMapping("/update")
    @ResponseBody
    public String updateComment(Comment comment){

        int i = commentService.updateComment(comment);
        if (i==1) {
            return "success updated";
        }else {
            return "fail update";
        }

    }

    @PostMapping("/add")
    //@GetMapping("/update")
    @ResponseBody
    public String addComment(Comment comment){

        int i = commentService.addComment(comment);
        if (i==1) {
            return "success add";
        }else {
            return "fail add";
        }

    }*/

    @GetMapping("/get/{id}")
    @ResponseBody
    public Comment findById(@PathVariable("id") int comment_id) {
        Comment comment = commentService.findById(comment_id);
        return comment;
    }
    @GetMapping("/update/{id}/{author}")
    public Comment updateComment(@PathVariable("id") int comment_id, @PathVariable("author") String author) {
        Comment comment = commentService.findById(comment_id);
        comment.setAuthor(author);
        Comment updateComment = commentService.updateComment(comment);
        return updateComment;
    }
    @GetMapping("/delete/{id}")
    public void deleteComment(@PathVariable("id") int comment_id) {
        commentService.deleteComment(comment_id);
    }
}